<script setup lang="ts">
import { ref } from 'vue'

const list = ref([
  { id: 1, name: '《红楼梦》', author: '曹雪芹' },
  { id: 2, name: '《西游记》', author: '吴承恩' },
  { id: 3, name: '《水浒传》', author: '施耐庵' },
  { id: 4, name: '《三国演义》', author: '罗贯中' }
])


// 删除逻辑
const delBook= (id:number)=>{
// 把传入过来的id 专程为数组的下标
const index = list.value.findIndex(item => item.id == id)
// 删除对应的 数据 根据下标
list.value.splice(index , 1)
}
</script>


<template>
  <div id="app">
    <h3>小黑的书架---ref写法</h3>
    <ul>
      <li v-for="item in list" :key="item.id">
        <span>{{item.name}}</span>
        <span>{{item.author}}</span>
        <button @click="delBook(item.id)">删除</button>
      </li>
    </ul>
  </div>

  <h3>小黑的书架---reactive写法区别就是.value</h3>
</template>

<style></style>